home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr28 / sc3x02.zip / CUSEFILE.C < prev    next >
Text File  |  1993-03-01  |  6KB  |  153 lines

  1. //   ╔════════════════════════════════════════════════════════════════════╗
  2. //   ║                                                                    ║
  3. //   ║ module:      3xsc.c                                                ║
  4. //   ║ abstract:    This module shows how to make 3.x system calls using  ║
  5. //   ║              the F2 Shell Interface.  Obviously, it requires the   ║
  6. //   ║              NetWare Shell.                                        ║
  7. //   ║                                                                    ║
  8. //   ║ environment: NetWare 3.x v3.11                                     ║
  9. //   ║              Borland C 3.0                                         ║
  10. //   ║                                                                    ║
  11. //   ║  This software is provided as is and carries no warranty           ║
  12. //   ║  whatsoever.  Novell disclaims and excludes any and all implied    ║
  13. //   ║  warranties of merchantability, title and fitness for a particular ║
  14. //   ║  purpose.  Novell does not warrant that the software will satisfy  ║
  15. //   ║  your requirements or that the software is without defect or error ║
  16. //   ║  or that operation of the software will be uninterrupted.  You are ║
  17. //   ║  using the software at your risk.  The software is not a product   ║
  18. //   ║  of Novell, Inc. or any of subsidiaries.                           ║
  19. //   ║                                                                    ║
  20. //   ║      ****    NOTICE    ****    NOTICE   ****   NOTICE   ****       ║
  21. //   ║                                                                    ║
  22. //   ║  This example code has not been extensively tested and therefore   ║
  23. //   ║  should be run on a test server before used in a production en-    ║
  24. //   ║  vironment.  Also, a backup is recommended before the installation ║
  25. //   ║  of any untested component.                                        ║
  26. //   ╟────────────────────────────────────────────────────────────────────╢
  27. //   ║ maintenance history:                                               ║
  28. //   ║ level    date      pi   description                                ║
  29. //   ╟────────────────────────────────────────────────────────────────────╢
  30. //   ║  001   10/01/92    cm   Intial release.                            ║
  31. //   ╚════════════════════════════════════════════════════════════════════╝
  32.  
  33. #include <stdio.h>
  34. #include <string.h>
  35. #include <stdlib.h>
  36. #include <dos.h>
  37. #include "nwsys.h"
  38. #include <share.h>
  39. #include <fcntl.h>
  40. #include <sys/stat.h>
  41.  
  42. //
  43. //  First of all, we define the request and reply structures which are
  44. //  needed for the ScanConnectionsUsingFile API call.  These structures are
  45. //  layed out according to the System Call documentation.
  46. //
  47.  
  48. struct  {
  49.      WORD    sflen;          // length of the structure
  50.      BYTE    sfcode;         // the subfunction code
  51.      BYTE    forkType;       // type of file
  52.      BYTE    volumeNumber;   // volume number
  53.      LONG    sequenceNumber; // dirEntry sequence number
  54.      WORD    lastRecordSeen; // last record
  55. } Request;
  56.  
  57. typedef struct {
  58.     WORD    connectionNumber;  // connection number holding file open
  59.     WORD    taskNumber;        // task holding file open
  60.     BYTE    lockType;          // lock type
  61.     BYTE    accessFlag;        // access
  62.     BYTE    lockFlag;          // lock flag
  63. } CONN_INFO;
  64.  
  65. struct {
  66.     WORD     nextRequest;       // next record
  67.     WORD  useCount;          // use count
  68.     WORD  openCount;         // total times file is open
  69.     WORD    openForReadCount;  // total open for read
  70.     WORD    openForWriteCount; // total open for write
  71.     WORD  denyReadCount;     // deny read flag/total
  72.     WORD  denyWriteCount;    // deny write flag/total
  73.     BYTE    locked;            // lock status
  74.     BYTE     fork;              // file type
  75.     WORD    connCount;         // number of connection entries
  76.     CONN_INFO
  77.             connInfo[70];      // individual connection info
  78. } Reply;
  79.  
  80. //
  81. //  This is the main program.  The purpose is to make the ScanConnections
  82. //  UsingFiles API call to illustrate making system calls using the F2
  83. //  interface.
  84. //
  85.  
  86. int main(int argc, char *argv[])
  87. {
  88.     int   cc;
  89.     char    dirPath[255];
  90.     BYTE    volumeNumber;
  91.     LONG    sequenceNumber;
  92.     int    fileHandle;
  93.  
  94.     if(argc!=2){printf("usage: 3xsc FullPath\n");exit(1);}
  95.     strcpy(dirPath,argv[1]);
  96.     fileHandle=sopen(dirPath,O_TEXT | SH_DENYNO, S_IREAD | S_IWRITE);
  97.     if(fileHandle == -1) {
  98.         printf("\nUnable to open %s.",dirPath);
  99.         exit(1);
  100.     }
  101.     //
  102.     //  Build the request buffer
  103.     //
  104.     cc=ConvertPathToDirEntry(dirPath, &volumeNumber, &sequenceNumber);
  105.     if( cc ) {
  106.         printf("%s not Found.",dirPath);
  107.         exit(1);
  108.     }
  109.     Request.sflen = (sizeof Request) ;
  110.     Request.sfcode = 236;                       // subfunction code
  111.     Request.forkType = 0;
  112.     Request.volumeNumber = volumeNumber;
  113.     Request.sequenceNumber = sequenceNumber;
  114.     Request.lastRecordSeen = 0;
  115.     cc = NWSystemCall(23,&Request,sizeof Request,&Reply,sizeof Reply);
  116.     printf("Function returned:    %03d--%#02x\n",cc,cc);
  117.     printf("\nPress any key to close file!");
  118.     getch();
  119.     close(fileHandle);
  120.     return 0;
  121. }
  122.  
  123. ConvertPathToDirEntry(char *path, BYTE *volume, LONG *dirEntry)
  124. {
  125.     static struct {
  126.         WORD  sflen;          // length of the structure
  127.         BYTE  sfcode;         // the subfunction code
  128.         BYTE  dirHandle;      // type of file
  129.         BYTE  pathStringLength;
  130.                             // length of path
  131.         BYTE    pathString[255];
  132.                             // path
  133.     } dirEntryRequest;
  134.  
  135.    static struct {
  136.         BYTE    volumeNumber;   // volume number
  137.         LONG    dirEntry;       // directory entry sequence
  138.     } dirEntryReply;
  139.     int    cc;
  140.  
  141.     dirEntryRequest.sflen=sizeof(dirEntryRequest);
  142.     dirEntryRequest.sfcode=0xF4;
  143.     dirEntryRequest.dirHandle=0x00;
  144.     dirEntryRequest.pathStringLength=strlen(path);
  145.     memcpy(&dirEntryRequest.pathString,path,strlen(path));
  146.     cc = NWSystemCall(23,&dirEntryRequest,sizeof dirEntryRequest,&dirEntryReply,sizeof dirEntryReply);
  147.     if( !cc) {
  148.         *volume=dirEntryReply.volumeNumber;
  149.         *dirEntry=dirEntryReply.dirEntry;
  150.     }
  151.     return( cc );
  152. }
  153.